<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8">
	<meta content="text/html;charset=UTF-8"/>
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
	<meta http-equiv ="Pragma" content = "no-cache"/>
	<meta http-equiv="Cache-Control" content="no cache" />
	<meta http-equiv="Expires" content="0" />
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
	<meta name="apple-mobile-web-app-status-bar-style" content="black"/>
	<meta name="apple-mobile-web-app-capable" content="yes"/>
	<meta name="format-detection" content="telephone=no"/>
	<script src="https://cdn.bootcss.com/pace/1.0.2/pace.min.js"></script>
	<link href="https://cdn.bootcss.com/pace/1.0.2/themes/pink/pace-theme-flash.css" rel="stylesheet">
	<link rel="stylesheet" type="text/css" href="../../plugins/layui/css/layui.css" media="all"/>
	<link rel="stylesheet" type="text/css" href="../../css/fs.css" media="all"/>
	<script type="text/javascript" src="../../plugins/jquery/jquery.min.js"></script>
	<script type="text/javascript" src="../../plugins/home/common.js"></script>
	<script src="https://cdn.bootcss.com/layer/2.3/layer.js"></script>
	<script type="text/javascript" src="../../plugins/layui/layui.js"></script>
	<script type="text/javascript" src="../../plugins/frame/js/fsDict.js"></script>
	<script type="text/javascript" src="../../plugins/frame/js/fs.js"></script>
	<script type="text/javascript" src="../../plugins/frame/js/frame.js"></script>
	<script type="text/javascript" src="../../scripts/home/yunhetong.js"></script>
	<script type="text/javascript" src="../../scripts/home/magerIndcInfo.js"></script>
</head>
<body>
<div >
	<div class="layui-fluid">
		<div class="layui-row layui-col-space1">
			<div class="layui-col-md12">
				<div class="layui-form-query">
					<form class="layui-form" id="query_form">
						<input type="hidden" name="crmMagerId" id="crmMagerId"/>
						<input type="hidden" name="caCustId" id="caCustId"/>
						<div class="layui-form-item">
							<div class="layui-inline">
								<label class="layui-form-mid">合同模板名称：</label>
								<div class="layui-input-inline" style="width: 150px;">
									<input type="text" name="contractNm" autocomplete="off" class="layui-input" placeholder='请输入合同模板名称' />
								</div>
							</div>

							<div class="layui-inline">
								<div class="layui-input-inline">
									<button class="layui-btn" type="button" function="query"><i class="layui-icon">&#xe615;</i>查询</button>
								</div>
							</div>
						</div>
					</form>
				</div>
			</div>
			<div class="layui-col-md12">
				<div class="layui-row grid-demo" >
					<div class="layui-col-md12">
						<button class="layui-btn"  function="newAdd"  topTitle="新增">
							<i class="layui-icon">&#xe654;</i>新增
						</button>
						<button style="display: none" class="layui-btn layui-btn-danger" function="submit" url="/magerContDtl/delete.shtml" isMutiDml="1" isConfirm="1" confirmMsg="是否确定删除选中的数据？" inputs="crmMagerId:">
							<i class="layui-icon">&#xe640;</i>批量删除
						</button>
						<button style="display: none" class="layui-btn" function="refresh" id="refresh">
							<i class="layui-icon">&#x1002;</i>刷新
						</button>
						<!--<button class="layui-btn" function="kfapp">
							<i class="layui-icon">&#xe756;</i>测试
						</button>-->
					</div>
					<div class="layui-col-md12">
						<table id="fsDatagrid" lay-filter="fsDatagrid" class="fsDatagrid" isLoad="1" url="/magerContDtl/findAllListPage.shtml" isPage="1" sortType="1" defaultForm="query_form" height="full-135"></table>

						<div class="fsDatagridCols">
							<p type="numbers" title="序号"/>
							<!--<p checkbox="true"/>-->
							<p field="contractNm" title="模板名称" width="200"  templet="#prodNmTpl"/>
							<!--<p field="contractAdd" title="模板地址" width="160" sort="true"/>-->
							<p field="createDt" title="上传时间" width="160" sort="true"/>
							<p field="prodNm" title="已应用产品" width="360"/>
							<p fixed="right" align="center" width="160" toolbar="#barDemo" title="操作"/>
						</div>
						<script type="text/html" id="barDemo">
				{{# if(d.prodNm!=''){}}
				{{#} else {}}
				   <a id="del" class="layui-btn layui-btn-xs layui-btn-danger" lay-event="submit" isConfirm="1" url="/magerContDtl/delete.shtml" inputs="contractId:">删除</a>
				{{#}}}


						</script>
						<script type="text/html" id="prodNmTpl">
							<a href="{{d.contractAdd}}">{{d.contractNm}}</a>
						</script>
					</div>
				</div>
			</div>
		</div>
	</div>
</div>
<button class="layui-btn demoMore"  id="uploadBtn" style="display: none">添加</button>
<script type="text/javascript">
    var domain=getDomain();
    var token=getLongToken();
    var operatorId=getCurrentLoginUser();
    var uploadInst='';//创建一个实例
	var uploadType="E1";
    //$("#fsDatagrid").attr('url',domain+url);
    layui.use(['upload','form'], function(){
        var form = layui.form;
        var $ = layui.jquery
            ,upload = layui.upload;
        //同时绑定多个元素，并将属性设定在元素上,限制docx
        uploadInst=upload.render({
            elem: '.demoMore'
            ,url:domain+'/api/upload/one'
            ,accept: 'file' //普通文件
            ,data:{}
            ,auto: true
            // ,exts: 'zip|rar|7z' //只允许上传压缩文件
            ,exts: 'docx' //只允许上传压缩文件
            ,multiple: false
            ,size: 1024 //限制文件大小，单位 KB
            ,before: function(obj){
                //layer.tips('接口地址：'+ this.url, this.item, {tips: 1});
                layer.load(); //上传loading

            }
            ,done: function(res, index, upload){
                var item = this.item;
                var fileId=res.data.fileId;
                var fileName=res.data.oriFileName;
                var fileUrl=res.data.fileUrl;
                crmMagerId=res.data.crmMagerId;
                caCustId=res.data.caCustId;
                console.log(JSON.stringify(res)); //获取当前触发上传的元素，layui 2.1.0 新增
                //关闭loading
                layer.closeAll('loading');
                if(res.code==0){
                    addTemplate(crmMagerId,uploadType,caCustId,fileId,fileName,fileUrl);
                }else{
                    messageErrorInfo(res.message);
                    return;
                }

            }
            ,error:function(){
                layer.closeAll('loading');
                messageErrorInfo("接口返回异常")
            }
        });

    });
    layui.fsButton.newAdd = function(elem,data,datagrid){
        var caCustId=$("#caCustId").val();
        var crmMagerId=$("#crmMagerId").val();
        uploadInst.reload({
            accept: 'file' //只允许上传图片
            ,size: 1024*10 //限定大小
            ,exts: 'docx' //只允许上传压缩文件
            ,data:{token:token,"operatorId":operatorId,"caCustId":caCustId,"type":uploadType,"crmMagerId":crmMagerId}
        });
        $("#uploadBtn").click();

    }
    /**
     * 刷新列表
     * @param datagrid
     */
    layui.fsButton.refresh = function(elem,data,datagrid){
        datagrid.reload();
    }
</script>
</body>
</html>

